package it.polimi.TravelDreamEAR.ejb.entities;

import it.polimi.TravelDreamEAR.ejb.sessionBeans.*;
import it.polimi.TravelDreamEAR.ejb.sessionBeans.dto.*;

import java.io.Serializable;

import javax.persistence.*;

import org.apache.commons.codec.digest.DigestUtils;

import java.util.List;


/**
 * The persistent class for the utenti database table.
 * 
 */
@Entity
@NamedQuery(name="Utenti.findAll", query="SELECT u FROM Utenti u")
public class Utenti implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	private String username;

	private String password;

	@ElementCollection(targetClass = Gruppi.class)
    @CollectionTable(name = "UTENTI_GRUPPI",
                    joinColumns = @JoinColumn(name = "utente"))
    @Enumerated(EnumType.STRING)
    @Column(name="gruppo")
    private List<Gruppi> gruppi;

	public Utenti() {
	}
	
	public Utenti(ClienteDTO clienteDTO) {
		this.username=clienteDTO.getUsername();
		this.password=DigestUtils.sha256Hex(clienteDTO.getPassword());
	}
	
	public Utenti(ImpiegatoDTO impiegatoDTO) {
		this.username=impiegatoDTO.getUsername();
		this.password=DigestUtils.sha256Hex(impiegatoDTO.getPassword());
	}

	public String getUsername() {
		return this.username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public List<Gruppi> getGruppi() {
		return this.gruppi;
	}

	public void setGruppi(List<Gruppi> gruppi) {
		this.gruppi = gruppi;
	}

}